<template>
  <div class="search_continer">
    <div class="search_continer_title">查询栏</div>
    <!-- 查询输入项 ----------------------------------------------------------------------------------->
    <div class="search_continer_myInput">
      <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称" />
    </div>
    <div class="search_continer_myInput">
      <el-select v-model="queryParams.grade" filterable placeholder="请选择评级">
        <el-option v-for="item in options" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue">
        </el-option>
      </el-select>
    </div>
    <!-- -------------------------------------------------------------------------------------------->
    <el-button type="primary" icon="el-icon-search" @click="handleQueryClick">查询</el-button>
    <el-button icon="el-icon-refresh-left" @click="handleReset">重置</el-button>
  </div>
</template>

<script>
import { listDictionary } from '@/api/purchasing/supplier'

export default {
  name: 'SearchBar',
  data () {
    return {
      /** 查询参数 --------------------------------------------------------------------------------- */
      queryParams: {
        supplierName: null,
        grade: null,
      },
      /**  ------------------------------------------------------------------------------------------ */
      options: []
    }
  },
  mounted () {
    this.handleListDictionary()
  },
  methods: {
    handleQueryClick () {
      this.$emit('query_click', this.queryParams)
    },
    async handleListDictionary () {
      const { data: res } = await listDictionary({ dictType: 'supplier_grade', status: 0 })
      this.options = res
    },
    handleReset () {
      for (const k in this.queryParams) {
        this.queryParams[k] = null
      }
      this.$emit('reset_click')
    }
  }
}
</script>
<style lang="scss" scoped>
.search_continer {
  padding: 10px;
  margin-bottom: 20px;
  display: flex;
  background-color: white;
  border-radius: 5px;

  &_title {
    line-height: 36px;
    padding: 0 20px 0 0;
    font-weight: bold;
  }

  &_myInput {
    padding-right: 20px;
  }
}
</style>
